package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author: 课工场
 * @since 2023/9/1
 */
@RequestMapping("order")
@RestController
@Slf4j
public class OrderController {

    @Value("${server.port}")
    private String port;

    @GetMapping("m1")
    public String method1(){

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "OrderController method1 ok port = "+port;
    }

    @GetMapping("m2")
    public String method2(Integer id){
        log.info("======== orderController id======= {} ",id);
        return "OrderController method2 ok port = "+port;
    }

    @GetMapping("m3/{id}")
    public String method3(@PathVariable("id") Integer id){
        log.info("======== orderController id======= {} ",id);
        return "OrderController method3 ok port = "+port;
    }

    @GetMapping("m4")
    public String method4(Integer[] ids){
        for (Integer id : ids) {
            log.info("orderController id = {}",id);
        }
        return "OrderController method4 ok port = "+port;
    }

    // id=10&productName=手机
    @GetMapping("m5")
    public String method5(Order order){
        log.info("orderController order = {}",order);
        return "OrderController method5 ok port = "+port;
    }

    @PostMapping("m6")
    public String method6(@RequestBody Order order){
        log.info("orderController order = {}",order);
        return "OrderController method6 ok port = "+port;
    }

    @GetMapping("m7")
    public Order method7(Integer id){
        Order order = new Order();
        order.setId(id);
        order.setProductName("mate60");
        return order;
    }
}
